# Definition for singly-linked list.
class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next
from typing import Optional


class Solution:
    def mergeTwoLists(self, list1: Optional[ListNode], list2: Optional[ListNode]) -> Optional[ListNode]:
        resNode = ListNode(0,None)
        while list2 is not None and list1 is not None:
            if list2.val > list1.val:
                resNode.val = list1.val
                list1 = list1.next
                resNode.next =None
            else:
                resNode.val = list2.val
                list2 = list2.next





if __name__ == '__main__':
    list1 =[1,2,4]
    list2 = [1,3,4]

    val = Solution.mergeTwoLists(list1,list2)
    print(val)
